<?php

define('PRESSLESS_IS_RUNNING', TRUE);

require(dirname(__FILE__).'/initialize.php');

$resource_classes['pressless_env'] = PRESSLESS_ENV;

@include(PRESSLESS_CUSTOM_DIR.'/dispatch.php');

//
// Below are things that need to be set if the custom dispatcher didn't do so already
//

if ( !defined('PRESSLESS_LANG') )
  define('PRESSLESS_LANG', 'en_US');

// No action has been defined from the custom dispatcher?
if ( !defined('PRESSLESS_ACTION') )
{
  $matches = array();
  if ( preg_match('#^/pressless/source(/.*)#', $_SERVER['PATH_INFO'], &$matches) )
  {
    define('PRESSLESS_ACTION', 'pressless-source');
    $_GET['source_file'] = $matches[1];
  }

  // Has no action been defined yet by the custom dispatch rules?
  if ( !defined('PRESSLESS_ACTION') ) {
    define('PRESSLESS_ACTION', pressless_action_match());
  }
} // if ( !defined('PRESSLESS_ACTION') )

//
// Below are things that have to happen for each action
//

require($pressless_action_files[PRESSLESS_ACTION . '/handler.php']);

// Load and execute the action handler class if it has been defined in the handler
$action_handler_class_name = str_replace('-', '_', PRESSLESS_ACTION) . "_Action_Handler";
if ( class_exists($action_handler_class_name) )
{
  $action_handler = new $action_handler_class_name();
  $action_handler->handle_request();
}

exit(0);

?>
